﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TidyBlog.Data
{
    public class SQLitePagingHelper<T> : PagingHelper<T> where T : new()
    {
        protected override List<T> GetData(ushort pageSize, int currentPage)
        {
            var cmdText = new StringBuilder(SQLCommand.Top(0).ToString());

            // 分页
            cmdText.Append(" LIMIT ");
            if (currentPage > 1)
            {
                cmdText.Append((currentPage - 1) * pageSize);
                cmdText.Append(",");
            }
            cmdText.Append(pageSize);

            Cmd.CommandText = cmdText.ToString();

            return SimpleORM<T>.DataReaderToEntityList(
               DbHelper.ExecuteReader(Cmd)
            );
        }
    }
}